package com.cm.tianwt.socks.utils;

public class LogUtils {
	
	
	public final static int LEVEL_DEBUG = 1;
	public final static int LEVEL_INFO = 2;
	public final static int LEVEL_ERROR = 3;
	public final static int LEVEL_HIGEST = 4;
	
	
	private static int level = LEVEL_DEBUG;
	
	public static void setLevel(int level) {
		LogUtils.level = level;
	}
	
	public static void D(String msg) {
		
		String tag = getStackName();
		D(tag,msg);
		
	}

	public static void I(String msg) {
		
		String tag = getStackName();
		I(tag,msg);
		
	}

	public static void E(String msg) {
	
		String tag = getStackName();
		D(tag,msg);
	
	}

	private static String getStackName() {
		String tag = "Socks";
		StackTraceElement[] trace = Thread.currentThread().getStackTrace();
		if(trace==null ||  trace.length<2) {
			tag = trace[2].getFileName();
		};
		return tag;
	}

	public static void  D(String tag,String msg) {
		if(level<=LEVEL_DEBUG)
		{
			System.out.println(String.format("DEBUG [%s] %s", tag,msg));
		}
	}

	public static void  E(String tag,String msg) {
		if(level<=LEVEL_ERROR)
		{
			System.err.println(String.format("Error [%s] %s", tag,msg));
		}
		
	}

	public static void  I(String tag,String msg) {
		if(level<=LEVEL_INFO)
		{
			System.out.println(String.format("INFO [%s] %s", tag,msg));
		}
		
	}

}
